package Psy_Admin_Page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class SupervisorPage extends StaffPage{
    @Override
    //点击修改 默认第一个
    public SupervisorPage clickEdit(){
        waitForWindow(2000);
        driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(10) > div:nth-child(1) > div:nth-child(1) > button:nth-child(1)")).click();
        return this;
    }

    @Override
    //输入工作单位
    public StaffPage inputWorkPlace(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).sendKeys(keys);
        return this;
    }

    @Override
    //修改工作单位
    public StaffPage editWorkplace(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputWorkPlace(keys).confirmAdd();
        return this;
    }

    @Override
    //获取工作单位
    public String getWorkplace(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(7) > div:nth-child(1) > span:nth-child(1)")).getText();
    }


    @Override
    //输入职称
    public StaffPage inputJobTitle(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[8]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[8]")).sendKeys(keys);
        return this;
    }

    @Override
    //修改职称
    public StaffPage editJobTitle(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[8]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputJobTitle(keys).confirmAdd();
        return this;
    }

    @Override
    //获取职称
    public String getJobTitle(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(6) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //选择资质--only督导
    public SupervisorPage selectQuality(String keys){
        waitForWindow(2000);
        //空则不选择督导资质
        if(keys == "") {
        }
        //选择一级
        else if(keys == "1"){
            //下拉
            driver.findElement(By.xpath("(//input[@type='text'])[9]")).click();
            driver.findElement(By.cssSelector("div.el-select-dropdown:nth-child(11) > div:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1)")).click();
            //driver.findElement(By.xpath("//li[contains(.,'一级')]")).click();
        }
        //选择二级
        else if(keys == "2"){
            //下拉
            driver.findElement(By.xpath("(//input[@type='text'])[9]")).click();
            driver.findElement(By.cssSelector("div.el-select-dropdown:nth-child(11) > div:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(2)")).click();
        }
        return this;
    }

    //获取当前督导资质选择框内的值
    public String getQuality(){
        //进入到修改页面看是否有实质的修改
        waitForWindow(2000);
        clickEdit();
        waitForWindow(2000);
        return driver.findElement(
                By.cssSelector("div.el-select:nth-child(1) > div:nth-child(1) > input:nth-child(1)")).getAttribute("value");
    }

    //新增督导 输入信息的方法 10个参数
    public String inputAll(String name, String phoneNum, String ID,
                                   String Email, String jobTitle, String quality,
                                   String qualityNum, String workplace, String username, String password){
        inputName(name).
        inputPhoneNum(phoneNum).
        inputID(ID).
        inputEMail(Email).
        inputJobTitle(jobTitle);
        selectQuality(quality).
        inputQualityNum(qualityNum).
        inputWorkPlace(workplace).
        inputUsername(username).
        inputPassword(password);
        confirmAdd(); //最后点击确认添加
        String info = getErrorMessage();
        return info;
    }

    /**
     * 用于维护 所有错误提示信息的输出，重写getErrorMessage
     * 因为有10个输入框，因此有10个错误提示消息的维护
     * @return
     */
    @Override
    public String getErrorMessage() {
        waitForWindow(2000);
        String info = "";
        //name错误提示消息的css选择器
        By.ByCssSelector nameError = new By.ByCssSelector(".el-row:nth-child(1) > .el-col:nth-child(1) .el-form-item__error");
        if(isElementExist(driver,nameError)){
            WebElement element = driver.findElement(nameError);
            waitForWindow(500);
            String text = "姓名：" + element.getText();
            info = info + (text + '\n');
        }

        //phoneNum错误提示消息的css选择器
        By.ByCssSelector phoneNumError = new By.ByCssSelector(".el-row:nth-child(1) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,phoneNumError)){
            WebElement element = driver.findElement(phoneNumError);
            waitForWindow(500);
            String text = "电话：" + element.getText();
            info = info + (text + '\n');
        }

        //ID错误提示消息的css选择器
        By.ByCssSelector IDError = new By.ByCssSelector(".el-row:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,IDError)){
            WebElement element = driver.findElement(IDError);
            waitForWindow(500);
            String text = "身份证号：" + element.getText();
            info = info + (text + '\n');
        }

        //Email错误提示消息的css选择器
        By.ByCssSelector EmailError = new By.ByCssSelector(".el-row:nth-child(3) > .el-col:nth-child(1) .el-form-item__error");
        if(isElementExist(driver,EmailError)){
            WebElement element = driver.findElement(EmailError);
            waitForWindow(500);
            String text = "邮箱：" + element.getText();
            info = info + (text + '\n');
        }

        //JobTitle错误提示消息的css选择器
        By.ByCssSelector JobTitleError = new By.ByCssSelector(".el-row:nth-child(3) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,JobTitleError)){
            WebElement element = driver.findElement(JobTitleError);
            waitForWindow(500);
            String text = "职称：" + element.getText();
            info = info + (text + '\n');
        }

        //Quality错误提示消息的css选择器
        By.ByCssSelector QualityError = new By.ByCssSelector(".searchSelect .el-form-item__error");
        if(isElementExist(driver,QualityError)){
            WebElement element = driver.findElement(QualityError);
            waitForWindow(500);
            String text = "督导资质：" +element.getText();
            info = info + (text + '\n');
        }

        //QualityNum错误提示消息的css选择器
        By.ByCssSelector QualityNumError = new By.ByCssSelector(".el-row:nth-child(4) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,QualityNumError)){
            WebElement element = driver.findElement(QualityNumError);
            waitForWindow(500);
            String text = "资质编号：" +element.getText();
            info = info + (text + '\n');
        }

        //Workplace错误提示消息的css选择器
        By.ByCssSelector WorkplaceError = new By.ByCssSelector(".el-row:nth-child(5) .el-form-item__error");
        if(isElementExist(driver,WorkplaceError)){
            WebElement element = driver.findElement(WorkplaceError);
            waitForWindow(500);
            String text = "工作单位：" +element.getText();
            info = info + (text + '\n');
        }

        //Username错误提示消息的css选择器
        By.ByCssSelector UsernameError = new By.ByCssSelector(".el-row:nth-child(6) .el-form-item__error");
        if(isElementExist(driver,UsernameError)){
            WebElement element = driver.findElement(UsernameError);
            waitForWindow(500);
            String text = "用户名：" +element.getText();
            info = info + (text + '\n');
        }

        //Password错误提示消息的css选择器
        By.ByCssSelector PasswordError = new By.ByCssSelector(".el-row:nth-child(7) .el-form-item__error");
        if(isElementExist(driver,PasswordError)){
            WebElement element = driver.findElement(PasswordError);
            waitForWindow(500);
            String text = "密码：" +element.getText();
            info = info + (text + '\n');
        }
        waitForWindow(2000);
        return info;
    }

    public SupervisorPage clickSupervisorTab(){
        //选择督导tab
        waitForWindow(2000);
        driver.findElement(By.cssSelector(".leftActive > .el-col:nth-child(2)")).click();
        waitForWindow(1000);
        return this;
    }

}
